package edu.vu.colorsplosion;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;

public class HighScores extends Activity {
public SharedPreferences highscores;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        setVolumeControlStream(AudioManager.STREAM_MUSIC);
        highscores = getApplicationContext().getSharedPreferences("highscores", MODE_WORLD_READABLE);
        SharedPreferences.Editor mEd = highscores.edit();
        
        super.onCreate(savedInstanceState);
        Intent i = getIntent();
        int number = i.getIntExtra("number", -100);
        String name = i.getStringExtra("name");
        setContentView(R.layout.activity_high_scores);
        int score1 = highscores.getInt("score1", 5000);
        int score2 = highscores.getInt("score2", 4000);
        int score3 = highscores.getInt("score3", 3000);
        int score4 = highscores.getInt("score4", 2000);
        int score5 = highscores.getInt("score5", 1000);
        String[] names = new String[5];
        names[0] = highscores.getString("name1", "Colorsplosion");
        names[1] = highscores.getString("name2", "Colorsplosion");
        names[2] = highscores.getString("name3", "Colorsplosion");
        names[3] = highscores.getString("name4", "Colorsplosion");
        names[4] = highscores.getString("name5", "Colorsplosion");
        //Toast.makeText(getApplicationContext(), "Name is : [" + name + "]", Toast.LENGTH_SHORT).show();
        
        
        if ((number >= 1)&&(number <= 5)) {
            names[number-1] = name;
            mEd.putString("name"+number, name);
            mEd.commit();
        } else {
            //names[number-1] = "Unknown";
            //Toast.makeText(getApplicationContext(), "Number is : [" + number + "]", Toast.LENGTH_SHORT).show();
        }
        
        TextView proc = (TextView) findViewById(R.id.score1tv);
        proc.setText(""+score1);
        proc = (TextView) findViewById(R.id.name1tv);
        proc.setText(names[0]);
        
        proc = (TextView) findViewById(R.id.score2tv);
        proc.setText(""+score2);
        proc = (TextView) findViewById(R.id.name2tv);
        proc.setText(names[1]);
        
        proc = (TextView) findViewById(R.id.score3tv);
        proc.setText(""+score3);
        proc = (TextView) findViewById(R.id.name3tv);
        proc.setText(names[2]);
        
        proc = (TextView) findViewById(R.id.score4tv);
        proc.setText(""+score4);
        proc = (TextView) findViewById(R.id.name4tv);
        proc.setText(names[3]);
        
        proc = (TextView) findViewById(R.id.score5tv);
        proc.setText(""+score5);
        proc = (TextView) findViewById(R.id.name5tv);
        proc.setText(names[4]);
        if (savedInstanceState != null){
            if (savedInstanceState.containsKey("name"))
            {
                savedInstanceState.getString("name");
            }
        }
        
    }
    
    @Override
    public void onResume(){
        super.onResume();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_high_scores, menu);
        return true;
    }
}
